// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        prefabLeven: cc.Prefab,
        objPanel:cc.Node,
        //升级提示
        labelLevelTS:cc.Label,
        //用户当前关卡显示
        labelCurLevel:cc.Label,
        //关卡记录
        _curLevel:1,
    },



     onLoad () {
        //初始化配置
        window.initGameConfigData();
        cc.director.preloadScene("gameMain");
        this.init();
     },

     init(){
        this._curLevel=window.gameConfig.getGameData("level");
        this.labelCurLevel.string= "第"+this._curLevel+"关";//关卡
        let levelData=window.getGameLevelDataConfig(this._curLevel);
     },

    start() {

    },
    onJsonBtnClick(event) {
        let btnName = event.target.name;
        switch (btnName) {
            case "btn_xg":
                cc.log("加载选关界面");
                event.interactable = false;
                this.loadLevenToScene();
            break;

            case "btn_startGame":
                cc.log("开始游戏");
                event.interactable = false;
                this.gameStart();
            break;

            case "btn_rank":
                cc.log("开启排行榜");
                event.interactable = false;
                this.openRankLayer();
            break;  
            case "btn_rank":
                cc.log("开启排行榜");
                event.interactable = false;
                this.openRankLayer();
            break;  
            case "btn_rank":
                cc.log("开启排行榜");
                event.interactable = false;
                this.openRankLayer();
            break;  

            case "btn_rank":
                cc.log("开启排行榜");
                event.interactable = false;
                this.openRankLayer();
            break;  

            case "btn_rank":
                cc.log("开启排行榜");
                event.interactable = false;
                this.openRankLayer();
            break;  

            case "btn_rank":
                cc.log("开启排行榜");
                event.interactable = false;
                this.openRankLayer();
            break;  

            case "btn_rank":
                cc.log("开启排行榜");
                event.interactable = false;
                this.openRankLayer();
            break;  

            default:
                cc.log("无对应按钮");
                break;
        }
    },
    /**
     * 创建关卡
     */
    loadLevenToScene() {
        var objLeven = cc.instantiate(this.prefabLeven);
        objLeven.name="objLevel";
        this.node.addChild(objLeven);
        var objLevenCom = objLeven.getComponent("LevelScene");
        objLevenCom.createLevelLayer();
    },

    /**
     * 开始游戏
     */
    gameStart(){
        window.gameConfig.gameData.level=this._curLevel;
        cc.director.loadScene("gameMain");
    },

    /**
     * 打开排行榜
     */
    openRankLayer(){

    }
});